<?php

namespace Gds\ArticleBundle\Form;

use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolverInterface;
use Doctrine\ORM\EntityRepository;
class ArticleType extends AbstractType
{
    public function buildForm(FormBuilderInterface $builder, array $options)
    {
        $builder
            ->add('reference')
            ->add('designation')
            ->add('code_barre')
            ->add('taux_tva')
            ->add('remise')
            ->add('remise_max')
            ->add('prix_vente','text',array('label'=>'prix vente HT'))
                ->add('prix_achat_ht')
                ->add('unite')
            ->add('is_supprimer')
            ->add('famille', 'entity', array(
                    'label' => 'famille',
                    'class' => 'Gds\ArticleBundle\Entity\Famille',
                    'property' => 'libelle',
                    'query_builder' => function(EntityRepository $er) {
                        return $er->createQueryBuilder('f')
                                ->where('f.is_supprimer=:is_supprimer')
                                ->orderBy('f.libelle', 'ASC')
                            ->setParameter('is_supprimer',false);
                    },
                    'required' => true))
        ;
    }

    public function setDefaultOptions(OptionsResolverInterface $resolver)
    {
        $resolver->setDefaults(array(
            'data_class' => 'Gds\ArticleBundle\Entity\Article'
        ));
    }

    public function getName()
    {
        return 'gds_articlebundle_articletype';
    }
}
